<template>
  <div class="goods-num" @touchstart.stop>
    <div class="goods-num-top ">
      <div class="goods-num-top-content clearfix">
        <div class="img-par">
          <img :src="myData.goodsPic" alt="商品图片">
        </div>
        <div class="goods-price">
          <p class="num">￥{{myData.price}}</p>
          <p>库存 <span class="num">{{myData.stock}}</span> 件</p>
        </div>
        <i class="iconfont icon-guanbi" @touchstart="closeModal"></i>
      </div>

    </div>
    <div class="goods-num-select clearfix">
      <span>数量</span>
      <div class="num-select ">
        <a href="javaScript:;" :class="{'allow-click':myData.buyNum>1}" @touchstart="addGoodsNum(-1)">-</a>
        <input type="text" v-model="myData.buyNum" readonly="readonly">
        <a href="javaScript:;" class="allow-click" @touchstart="addGoodsNum(1)">+</a>
      </div>
    </div>
    <div class="goods-num-btn" @touchstart="confirmNum">确定</div>

  </div>
</template>

<script>
  export default {
    name: "goods-num-select",
    props: ["myData"],
    methods: {
      showMydata:function(){
        console.log(this.myData)
      },
      addGoodsNum: function (num) {
        if (num < 0 && this.myData.buyNum == 1) {
          this.myData.buyNum = 1;
          return;
        }
        this.myData.buyNum += num;
      },
      closeModal:function(){
        this.$parent.$parent.isShow=false;
      },
      confirmNum:function () {
        if(this.myData.addShopping){
          this.$http.get("http://192.168.1.108:3000/api/update?purchase="+this.myData.buyNum).then((data)=>{
            if(data.body.code==200){
              this.$parent.$parent.data.purchase=this.$parent.$parent.data.purchase-0+this.myData.buyNum
            }
          }).catch((error)=>{

          })
        }
        this.$parent.$parent.buyNum=this.myData.buyNum;
        this.$parent.$parent.isShow=false;
      }
    }
  }
</script>

<style scoped>
  .goods-num {
    position: absolute;
    width: 100%;
    background-color: white;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    z-index: 10000;
  }

  .goods-num-top {
    color: #797979;
    padding: 0 0.0266666rem;
  }

  .goods-num-top-content {
    border-bottom: 1px solid #eeeeee;
    padding-bottom: 0.0266666rem;
    position: relative;

  }

  .goods-num-top .img-par {
    padding: 2px;
    box-shadow: 0px 0px 20px 0px #f5f5f5;
    width: 0.15625rem;
    float: left;
    margin-top: -0.078125rem;
    background-color: #fff;
    border: 1px solid #eeeeee;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
  }

  .goods-num-top img {
    width: 100%;

  }

  .goods-num-top .goods-price {
    float: left;
    margin-left: 0.0266666rem;
  }

  .goods-num-top .goods-price p:nth-child(1) {
    margin-top: 6px;
  }

  .goods-num-top .goods-price .num {
    color: #f05656;
  }

  .goods-num-top i {
    position: absolute;
    right: 0;
    top: 50%;
    margin-top: -8px;
    color: #939393;
    font-weight: bold;
  }

  .goods-num-select {
    box-sizing: border-box;
    padding: 0.0266666rem;
    border: 1px solid #eee;
    margin-top: 0.0266666rem;
  }

  .goods-num-select span {
    float: left;
  }

  .goods-num-select .num-select {
    float: right;
  }

  .num-select {
    display: flex;
    flex-flow: row;
  }

  .num-select a {
    font-weight: 900;
    color: #ebebeb;
    text-decoration: none;
  }

  .num-select .allow-click {
    background-color: #f7f7f7;
    color: #999999;
  }

  .num-select a, .num-select input {
    flex-grow: 1;
    width: 0.09375rem;
    border: 1px solid #d7d7d7;
    text-align: center;
    box-sizing: border-box;
    height: 0.09375rem;
    line-height: 0.09375rem;
  }

  .num-select input {
    border: 0;
    width: 0.125rem;
    border-top: 1px solid #d7d7d7;
    border-bottom: 1px solid #d7d7d7;
    color: #666666;
  }

  .goods-num-btn {
    background-color: #fd5555;
    text-align: center;
    color: #fff;
    line-height: 40px;
    font-size: 0.04rem;
  }
</style>
